const { success, getGameAdderInfo } = require('../../../src/core/common')
const SaveDataMgr = require('../../../src/lib/save-data/manager')

/**
 *  add 命令
 */
async function addHandler(program) {
  program
    .command('add <gameName>')
    .description('加入游戏存档')
    .action(async (gameName) => {
      // 提示用户输入
      const { repoPath, dirName, dir } = await getGameAdderInfo()

      // 保存数据
      const newSetting = {
        gameName,
        repoPath,
        dirName,
        dirs: [dir]
      }

      const res = await SaveDataMgr.addOrUpdateSettings(newSetting)
      success(res)
    })
}

module.exports = addHandler
